<%@ page import="java.util.Date" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="appRoot" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Index</title>

    <base href="${appRoot}/">
    <script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<p>Hello Web!</p>
<p>
    <% Date now = new Date(); %>
    服务器时间：
    <fmt:formatDate value="<%=now%>" pattern="yyyy-MM-dd HH:mm:ss"/>1234
</p>
<input type="button" value="get" id="get"/>
<input type="button" value="post" id="post"/>
<input type="button" value="put" id="put"/>
<input type="button" value="putAll" id="putAll"/>
<input type="button" value="delete" id="delete"/>
<script type="text/javascript">
    $("#get").click(() => $.get("${appRoot}/api/persons", data => {
        console.log(data);
    }));
    $("#post").click(() => $.post("${appRoot}/api/persons", {name: "王五", birthday: "2018/2/5"}, data => {
        console.log(data);
    }));
    $("#put").click(() => $.ajax("${appRoot}/api/persons", {type:"put",data: {name: "王五", birthday: "2018/2/5"},success: data => {
        console.log(data);
    }}));
    $("#putAll").click(() => $.ajax("${appRoot}/api/persons", {contentType: "application/json; charset=utf-8", type:"put",data: JSON.stringify({name: "王五", birthday: "2018/2/5"}),success: data => {
        console.log(data);
    }}));
    $("#delete").click(() => $.ajax("${appRoot}/api/persons?id=1",{type:"delete", success:data => {
        console.log(data);
    }}));


</script>
</body>
</html>